package com.dgut.controller;

import com.dgut.dto.EmployeePageDTO;
import com.dgut.entity.Employee;
import com.dgut.result.PageResult;
import com.dgut.result.Result;
import com.dgut.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "员工管理接口")
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 分页查询员工信息
     *
     * @param employeePageDTO
     * @return
     */
    @ApiOperation("分页查询员工信息")
    @GetMapping("/page")
    public Result pageQuery(EmployeePageDTO employeePageDTO) {
        log.info("分页查询员工信息: 参数employeePageDTO:{}", employeePageDTO);
        PageResult pageResult = employeeService.pageQuery(employeePageDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增员工
     *
     * @param employee
     * @return
     */
    @PostMapping
    @ApiOperation("新增员工")
    public Result save(@RequestBody Employee employee) {
        log.info("新增员工: 参数employee:{}", employee);
        employeeService.save(employee);
        return Result.success();
    }

    /**
     * 删除员工
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除员工")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("删除员工: 参数ids:{}", ids);
        employeeService.delete(ids);
        return Result.success();
    }

    /**
     * 修改员工
     *
     * @param employee
     * @return
     */
    @PutMapping
    @ApiOperation("修改员工")
    public Result update(@RequestBody Employee employee) {
        log.info("修改员工: 参数employee:{}", employee);
        employeeService.update(employee);
        return Result.success();
    }

    @ApiOperation("查询所有销售人员")
    @GetMapping("/list")
    public Result list() {
        log.info("查询所有销售人员");
        List<Employee> list = employeeService.list();
        return Result.success(list);
    }
}
